"use strict"
const mvc = require("cosjs.mvc");
const handle = mvc.library("handle","查封账号","branch/accBlock")


exports.index = function(){
    let data= {"opensdk":this.library("opensdk/list") }
    return  handle.index.call(this,data);
}
exports.page = handle.page;

exports.save = async function () {
	let data = this.req.body;
	if (data.act == 'add') {
		data.time = Date.now();
	}

	await handle.save.call(this);

	if (data.act !== 'del') {
		let openidModel = mvc.model.branch("openid", this.branch);
		let query = {"openid": data.openid, "sdk": data.sdk};
		let option = {fields: {'guid': 1, gzone: 1}};
		let ret = await openidModel.find(query, option)
		if(ret) {
			/////////////踢下线///////////////
			for (let sid of ret.gzone) {
				await this.library("game/request", this.branch, sid, '/block/kickout', {guid: ret.guid});
			}
			/////////////踢下线///////////////
		}

	}

	return this.success()
}




